home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Devices / CD-ROM / iso9660 / Srcs / DialogUtils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-28  |  2.5 KB  |  102 lines  |  [TEXT/MPS ]

  1. /*
  2. from engber@gumball.ils.nwu.edu (Mike Engber):
  3.  
  4. Thanks for all the replys to my centering DLOG/ALRT question. I used the
  5. best ideas to synthesize my solution which I think elegant enough to be
  6. worth sharing. Attached are the relevant portions of my .h & .c files.
  7.  
  8. A couple of notes:
  9.  
  10. Several people`s solutions burned in the rsrc ids of the standard
  11. file dialogs. You may want to note that there are named constants for
  12. these values: putDlgID  & getDlgID.
  13.  
  14. All the solutions I was sent used screenBits.bounds. Is this what you
  15. want in a multi-monitor situation? If not, what should you do?
  16.  
  17. Feel free to use/modify/comment-on this code, especially if you notice
  18. any bugs or questionable practices.
  19.  
  20. -ME
  21. */
  22.  
  23. /* ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- */
  24.  
  25.  
  26. /* DialogUtils.c */
  27.  
  28. #include <QuickDraw.h>
  29. #include <Menus.h>
  30. #include <Resources.h>
  31. #include <StandardFile.h>
  32. #ifndef topLeft
  33. #define topLeft(r)    (((Point *)&(r))[0])
  34. #endif
  35. #ifndef botRight
  36. #define botRight(r)    (((Point *)&(r))[1])
  37. #endif
  38. #include "DialogUtils.h"
  39.  
  40. #include "DialogUtils.proto.h"
  41. static void DU_CenterRect(Rect *rect_p);
  42. static Point DU_Where(short rsrcId);
  43. static short DU_Center(ResType type, short rsrcId);
  44.  
  45. static void DU_CenterRect(Rect* rect_p){
  46. /*
  47.  * Aligns *rect_p wrt screenBits.bounds - LR centered & in upper 1/3
  48.  */
  49.  
  50.     /* exactly centered */
  51.     OffsetRect(rect_p,
  52.             (qd.screenBits.bounds.right + qd.screenBits.bounds.left)/2 -
  53.                 (rect_p->right + rect_p->left)/2
  54.         ,
  55.             (qd.screenBits.bounds.top + qd.screenBits.bounds.bottom)/2 -
  56.                 (rect_p->top + rect_p->bottom)/2
  57.         );
  58.     
  59.     /* up a bit */
  60.     OffsetRect(rect_p,0, 
  61.         GetMBarHeight() - 2*(rect_p->top - qd.screenBits.bounds.top)/3);
  62. }
  63.  
  64. static Point DU_Where(short rsrcId){
  65. /*
  66.  * Returns centering point for the topLeft corner of a dialog.
  67.  */
  68.     Handle  h = GetResource('DLOG',rsrcId);
  69.     Rect    r = {0,0,0,0};
  70.     if(h){
  71.         r = *((Rect*)(*h));
  72.         DU_CenterRect(&r);
  73.         ReleaseResource(h);
  74.     }
  75.     return topLeft(r);
  76. }
  77.  
  78. Point DU_StdPutWhere(void){
  79.     return DU_Where(putDlgID);
  80. }
  81.  
  82. Point DU_StdGetWhere(void){
  83.     return DU_Where(getDlgID);
  84. }
  85.  
  86. static short DU_Center(ResType type, short rsrcId){
  87. /*
  88.  * Reads in an 'ALRT' or 'DLOG' rsrc template & centers it's display Rect.
  89.  */
  90.     Handle  h = GetResource(type,rsrcId);
  91.     if(h) DU_CenterRect((Rect*)(*h));
  92.     return rsrcId;
  93. }
  94.  
  95. short DU_CenterALRT(short rsrcId){
  96.     return DU_Center('ALRT',rsrcId);
  97. }
  98.  
  99. short DU_CenterDLOG(short rsrcId){
  100.     return DU_Center('DLOG',rsrcId);
  101. }
  102.